package com.baidu.foodrecipe.utils

import android.animation.Animator
import android.animation.AnimatorSet
import android.animation.ObjectAnimator
import android.view.View

fun View.startScaleAnim(from: Float, to: Float,duration:Long = 500,onEnd:()->Unit = {}){
    val xAnim = ObjectAnimator.ofFloat(this, "scaleX", from,to).apply {
        this.duration = duration
    }
    val yAnim = ObjectAnimator.ofFloat(this, "scaleY", from,to).apply {
        this.duration = duration
    }
    AnimatorSet().apply {
        playTogether(xAnim,yAnim)
        addListener(object : Animator.AnimatorListener{
            override fun onAnimationStart(animation: Animator) {

            }

            override fun onAnimationEnd(animation: Animator) {
                onEnd()
            }

            override fun onAnimationCancel(animation: Animator) {

            }

            override fun onAnimationRepeat(animation: Animator) {

            }

        })
        start()
    }
}